home *** CD-ROM | disk | FTP | other *** search
- /* Interrupt handler support for Lattice C Version 2.1x */
- /*
- Author: Cheyenne Wills
- Addr: 12 West Locust St.
- Mechanicsburg Pa. 17055
-
- Compuserv [70376,555]
-
- December 1984
-
- Permission is granted to use, distribute and/or modify this code unless
- done for direct commercial profit.
- Author's name, address and this notice must be included in any copies.
-
- No guarantees or warranties of any kind: This code is distributed
- "AS IS" without any warranty. You are soley responsible for the
- selection of the program to achieve your intended results and for the
- results actually obtained.
-
- Any suggestions for improvements gratefully accepted
-
- */
-
- /* Compile with the -s option of the Lattice C compiler. */
- /* This is required because of pointer arithmetic in calling */
- /* an assembler subroutine. */
- /**
- *
- * name signal -- Initializes an interrupt to be processed by a
- * C function.
- * synopsis s = signal(func,stacksize,intnum);
- * type (*func)() - address of function to handle interrupt
- * unsigned stacksize - Size of stack to be used by interrupt handler
- * unsigned intnum - Interrupt number to process.
- * char *s - Pointer to the begining of the stack area
- * description This function installs a C function as an interrupt
- * handler. This is done by obtaining a small amount of
- * free storage as a stack and an interrupt boot strap.
- * The size of the stack is set by the caller. A couple of
- * extra bytes are added at the end of this stack area for
- * use of the interrupt boot strap.
- * The Interrupt boot strap is a small amount of assembly code
- * that calls a common assembly routine that establishes the
- * environment for C.
- * The following is the interrupt boot strap code:
- * +---------------------------------------------------------------------------+
- * | Stack Db Stacksize dup(?) ;Variable sized stack |
- * | XCINTBOO Proc Far |
- * | Call Far XCINTCOM ;Call Common code |
- * | Iret P |
- * | FuncIp Dw Offset Func ;Offset of C function to call |
- * | FuncCs Dw Segment Func ;Segment of C function to call |
- * | FuncSs Dw ? ;Stack segment of function |
- * | FuncDs Dw ? ;Data segment of function |
- * | XCINTBOO Endp |
- * +---------------------------------------------------------------------------+
- * XCINTCOM establishes the C enviroment and calls the actual
- * C function (XCINTCOM is a non public entry point).
- *
- * There are no args to the called C function, but the following
- * method can be used to obtain information about the
- * interrupt.
- * Take the address returned from SIGNAL add the size of the
- * stack and subtract 8 words (16 bytes) this will be the
- * address of the structure intinfo. If you notice, not all
- * of the registers are in this structure. The rest can be
- * found by taking data from Ss and Sp and using this as a
- * pointer (segment/offset) to the structure intinfo2.
- *
- * struct intinfo {
- * short Di; /* Di prior to interrupt */
- * short Si; /* Si prior to interrupt */
- * short Dx; /* Dx prior to interrupt */
- * short Cx; /* Cx prior to interrupt */
- * short Bx; /* Bx prior to interrupt */
- * short Ax; /* Ax prior to interrupt */
- * short Sp; /* Sp prior to interrupt (see note) */
- * short Ss; /* Ss prior to interrupt */
- * /* The following defines the interrupt boot code and should */
- * /* not be modified */
- * char FCALL[5]; /* Call to XCINTCOM */
- * char IRET; /* Iret instruction */
- * short FUNCIP; /* IP of function */
- * short FUNCCS; /* CS of function */
- * short FUNCDS; /* DS of function */
- * short FUNCSS; /* SS of function */
- * };
- *
- * Note: By using the data obtained from intinfo and Ss and Sp
- * you can obtain access to the following information:
- *
- * struct intinfo2 {
- * short Bx; /* Bx prior to interrupt */
- * short Ds; /* Ds prior to interrupt */
- * short Es; /* Es prior to interrupt */
- * short Bp; /* Bp prior to interrupt */
- * short Ip; /* Ip prior to interrupt <--+ Hardware */
- * short Cs; /* Cs prior to interrupt += generated */
- * short Flags; /* Flags prior to interrupt <--+ during int */
- * /* Anything following here belongs to the task that was interrupted */
- * }
- *
- * cautions:
- * It is the responsibility of the calling function to
- * save the current interrupt routines address, and to restore it.
- * It is also the responsibility of the calling function to
- * return the storage when its done. Take the original stack
- * size and add SIZE_OF_IBC then issue a rlsmem
- *
- * The minimum size of the stack is around 24 bytes.
- *
- **/
-
- #include <signal.h>
- extern char *getmem();
- char *signal(func,stack,vecno)
- int (*func)(); /* function which will process interrupt */
- unsigned stack; /* # of bytes of stack needed by function */
- unsigned vecno; /* # of vector for interrupt trap */
- {
- char *ustack;
- char *ibc;
-
- ustack=getmem(stack+SIZE_OF_IBC); /* this is where interrupt begins */
- ibc=ustack+stack;
- XCINTRIN(vecno,func,ibc);
- return ustack;
- }